*Analysis on the determinants of individual decisions to abandon the mainstream Left (Section 4)
*Based on 38 country-elections

use cses2to4_38cases, clear

*-------------------------------------------------------------------------------
*0. Preparation of variables
*-------------------------------------------------------------------------------

run 02a3a_Recoding_Abandon.do


*-------------------------------------------------------------------------------
*1. Trade-off analysis with the dichotomoy workers vs non-workers (clas2fin)
*-------------------------------------------------------------------------------

*11_3level: party compet
xtmelogit switch_x i.unionm i.clas2fin c.age i.gender i.educ ib4.locat c.c_inratiopool1 c.c_crl c.c_crr c.c_cg /// 
if clas2fin!=. & unionm!=. & age!=. & gender!=.  & locat!=. & educ!=. /// 
|| cntry: || cntelec: clas2fin , cov(un) 
estat icc
estadd scalar icc=r(icc2)
estimates store m11_3level

*12_3level: + crisis*PMincumbency + govtparty
xtmelogit switch_x i.unionm i.clas2fin c.age i.gender i.educ ib4.locat c.c_inratiopool1 c.c_crl c.c_crr c.c_cg i.crisisinc i.govtparty /// 
if clas2fin!=. & unionm!=. & age!=. & gender!=.  & locat!=. & educ!=. /// 
|| cntry: || cntelec: clas2fin , cov(un) 
estat icc
estadd scalar icc=r(icc2)
estimates store m12_3level

*13_3level: + interaction class*class profile
xtmelogit switch_x i.unionm i.clas2fin c.age i.gender i.educ ib4.locat c.c_inratiopool1 c.c_crl c.c_crr c.c_cg i.crisisinc i.govtparty c.c_inratiopool1#i.clas2fin /// 
if clas2fin!=. & unionm!=. & age!=. & gender!=.  & locat!=. & educ!=. /// 
|| cntry: || cntelec: clas2fin , cov(un) 
estat icc
estadd scalar icc=r(icc2)
estimates store m13_3level

*14_3level: + interaction class*class profile*union member
xtmelogit switch_x i.unionm i.clas2fin c.age i.gender i.educ ib4.locat c.c_inratiopool1 c.c_crl c.c_crr c.c_cg i.crisisinc i.govtparty c.c_inratiopool1#i.clas2fin /// 
c.c_inratiopool1#unionm unionm#i.clas2fin c.c_inratiopool1#unionm#i.clas2fin ///
if clas2fin!=. & unionm!=. & age!=. & gender!=.  & locat!=. & educ!=. /// 
|| cntry: || cntelec: clas2fin , cov(un) 
estat icc
estadd scalar icc=r(icc2)
estimates store m14_3level

*Appendix 6
esttab m11_3level m12_3level m13_3level m14_3level using Output1.rtf, replace se aic (1) bic (1) scalars(icc ll df_m) sfmt(3 1 0) b(3) nobaselevels nogaps /// 
transform (ln*: exp(@)^2 exp(@)^2) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) 


*Figures 2,4,5

set scheme s1mono

estimates restore m13_3level
quietly margins, dydx(clas2fin) at (c_inratiopool1=(-0.4(0.2)0.6)) level (95) predict(mu fixedonly) 
marginsplot, recast (line) yline(0) xsize (4.5) ysize (3.2)
graph save fig2a_3level, replace

estimates restore m13_3level
quietly margins clas2fin, at (c_inratiopool1=(-0.4(0.2)0.6)) predict(mu fixedonly)  
marginsplot, noci ysc(range(0.25 0.4)) ylabel(0.25 (0.05) 0.4) xsize (4.5) ysize (3.5)
graph save fig2b_3level, replace

estimates restore m14_3level
quietly margins clas2fin, at (c_inratiopool1=(-0.4(0.2)0.6) unionm=(0)) predict(mu fixedonly) /*Non-unionized*/
marginsplot, noci ysc(range(0.25 0.4)) ylabel(0.25 (0.05) 0.4) xsize (3) ysize (2.7)
graph save fig4a_3level, replace

estimates restore m14_3level
quietly margins clas2fin, at (c_inratiopool1=(-0.4(0.2)0.6) unionm=(1)) predict(mu fixedonly) /*Unionized*/
marginsplot, noci ysc(range(0.25 0.4)) ylabel(0.25 (0.05) 0.4) xsize (3) ysize (2.7)
graph save fig4b_3level, replace

estimates restore m14_3level 
quietly margins, dydx(clas2fin) at (c_inratiopool1=(-0.4(0.2)0.6) unionm=(0)) level (95) predict(mu fixedonly) /*Non-unionized - dydx*/
marginsplot, recast (line) yline(0) xsize (3) ysize (2.7) ysc(range(-0.15 0.1)) ylabel(-0.15 (0.05) 0.1)
graph save fig5a_3level_dydx, replace

estimates restore m14_3level
quietly margins, dydx(clas2fin) at (c_inratiopool1=(-0.4(0.2)0.6) unionm=(1)) level (95) predict(mu fixedonly)  /*Unionized - dydx*/
marginsplot, recast (line) yline(0) xsize (3) ysize (2.7) ysc(range(-0.15 0.1)) ylabel(-0.15 (0.05) 0.1) 
graph save fig5b_3level_dydx, replace

*-------------------------------------------------------------------------------
*2. Trade-off analysis with finer distinctions among other non-workers (clas3soc_wcserpro)
*-------------------------------------------------------------------------------

xtmelogit switch_x i.unionm ib1.clas3soc_wcserpro c.age i.gender i.educ ib4.locat c.c_inratiopool1 c.c_crl c.c_crr c.c_cg i.crisisinc i.govtparty c.c_inratiopool1#i.clas3soc_wcserpro /// 
if clas3soc_wcserpro!=. & unionm!=. & age!=. & gender!=.  & locat!=. & educ!=. /// 
|| cntry: || cntelec: clas3soc_wcserpro , cov(un)
estat icc
estadd scalar icc=r(icc2)
estimates store mstep2

*Figure 3
estimates restore mstep2
quietly margins clas3soc_wcserpro, at (c_inratiopool1=(-0.4(0.2)0.6)) predict(mu fixedonly) 
marginsplot, noci ysc(range(0.25 0.4)) ylabel(0.25 (0.05) 0.4) xsize (4.5) ysize (3.5) 
graph save fig3_3level, replace

*Appendix 8
estimates restore mstep2
mlincom, clear
margins, at (clas3soc_wcserpro=(1 2) c_inratiopool1=(-0.4 -0.2 0 0.2 0.4 0.6)) post predict(mu fixedonly) /* Difference socio-cu workers*/
mlincom (7-1) /*Diff at -0.4*/
mlincom (8-2) /*Diff at -0.2*/
mlincom (9-3) /*Diff at 0*/
mlincom (10-4) /*Diff at 0.2*/
mlincom (11-5) /*Diff at 0.4*/
mlincom (12-6) /*Diff at 0.6*/

estimates restore mstep2
mlincom, clear
margins, at (clas3soc_wcserpro=(1 3) c_inratiopool1=(-0.4 -0.2 0 0.2 0.4 0.6)) post predict(mu fixedonly) /*Difference other non-workers workers*/
mlincom (7-1) /*Diff at -0.4*/
mlincom (8-2) /*Diff at -0.2*/
mlincom (9-3) /*Diff at 0*/
mlincom (10-4) /*Diff at 0.2*/
mlincom (11-5) /*Diff at 0.4*/
mlincom (12-6) /*Diff at 0.6*/


*-------------------------------------------------------------------------------
*3. 3-way interaction with union membership (with clas3soc_wcserpro)
*-------------------------------------------------------------------------------

xtmelogit switch_x i.unionm ib1.clas3soc_wcserpro c.age i.gender i.educ ib4.locat c.c_inratiopool1 c.c_crl c.c_crr c.c_cg i.crisisinc i.govtparty c.c_inratiopool1#i.clas3soc_wcserpro /// 
c.c_inratiopool1#unionm unionm#i.clas3soc_wcserpro c.c_inratiopool1#unionm#i.clas3soc_wcserpro ///
if clas3soc_wcserpro!=. & unionm!=. & age!=. & gender!=.  & locat!=. & educ!=. /// 
|| cntry: || cntelec: clas3soc_wcserpro , cov(un)
estat icc
estadd scalar icc=r(icc2)
estimates store mstep3

*Appendix 7
esttab mstep2 mstep3 using Outputstep23.rtf, replace se aic (1) bic (1) scalars(icc ll df_m) sfmt(3 1 0) b(3) nobaselevels nogaps /// 
transform (ln*: exp(@)^2 exp(@)^2) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) 

*Table 4
*Workers
estimates restore mstep3
mlincom, clear
margins, at (unionm=(0 1) c_inratiopool1=(-0.4 -0.2 0 0.2 0.4 0.6) clas3soc_wcserpro=(1)) predict(mu fixedonly) post
mlincom (7-1) /*Diff at -0.4*/
mlincom (8-2) /*Diff at -0.2*/
mlincom (9-3) /*Diff at 0*/
mlincom (10-4) /*Diff at 0.2*/
mlincom (11-5) /*Diff at 0.4*/
mlincom (12-6) /*Diff at 0.6*/

*Socio-cultural professionals
estimates restore mstep3
mlincom, clear
margins, at (unionm=(0 1) c_inratiopool1=(-0.4 -0.2 0 0.2 0.4 0.6) clas3soc_wcserpro=(2)) predict(mu fixedonly) post
mlincom (7-1) /*Diff at -0.4*/
mlincom (8-2) /*Diff at -0.2*/
mlincom (9-3) /*Diff at 0*/
mlincom (10-4) /*Diff at 0.2*/
mlincom (11-5) /*Diff at 0.4*/
mlincom (12-6) /*Diff at 0.6*/

*Other non-workers
estimates restore mstep3
mlincom, clear
margins, at (unionm=(0 1) c_inratiopool1=(-0.4 -0.2 0 0.2 0.4 0.6) clas3soc_wcserpro=(3)) predict(mu fixedonly) post
mlincom (7-1) /*Diff at -0.4*/
mlincom (8-2) /*Diff at -0.2*/
mlincom (9-3) /*Diff at 0*/
mlincom (10-4) /*Diff at 0.2*/
mlincom (11-5) /*Diff at 0.4*/
mlincom (12-6) /*Diff at 0.6*/

